﻿using System;
using Plugins.Base;
using StockModel;
using Utils;

namespace TimeBarPlugin
{
	[Serializable]
	internal class DecisionEngineData : PropertyChangedNotifier, ICopyable<DecisionEngineData>
	{
		#region Attributes

		private EngineState _state;
		private decimal _startValue;
		private decimal _highThreshold;
		private decimal _lowThreshold;
		private decimal _stopLoss;
		private int _currentVolume;
		[NonSerialized] private Quotation _lastQuotation;
		private DateTime _processedDay;
		private EngineState _previousState;
		private decimal _max;
		private decimal _min;
		private decimal _maxProfitThreshold;
		private DateTime _blockStart;

		#endregion

		#region Properties

		public EngineState State
		{
			get
			{
				return _state;
			}
			set
			{
				if (_state != value)
				{
					_state = value;
					base.OnPropertyChanged("State");
				}
			}
		}

		public EngineState PreviousState
		{
			get
			{
				return _previousState;
			}
			set
			{
				if (_previousState != value)
				{
					_previousState = value;
					base.OnPropertyChanged("PreviousState");
				}
			}
		}

		public decimal StartValue
		{
			get
			{
				return _startValue;
			}
			set
			{
				if (_startValue != value)
				{
					_startValue = value;
					base.OnPropertyChanged("StartValue");
				}
			}
		}

		public decimal HighThreshold
		{
			get
			{
				return _highThreshold;
			}
			set
			{
				if (_highThreshold != value)
				{
					_highThreshold = value;
					base.OnPropertyChanged("HighThreshold");
				}
			}
		}

		public decimal LowThreshold
		{
			get
			{
				return _lowThreshold;
			}
			set
			{
				if (_lowThreshold != value)
				{
					_lowThreshold = value;
					base.OnPropertyChanged("LowThreshold");
				}
			}
		}

		public decimal StopLoss
		{
			get
			{
				return _stopLoss;
			}
			set
			{
				if (_stopLoss != value)
				{
					_stopLoss = value;
					base.OnPropertyChanged("StopLoss");
				}
			}
		}

		public int CurrentVolume
		{
			get
			{
				return _currentVolume;
			}
			set
			{
				if (_currentVolume != value)
				{
					_currentVolume = value;
					base.OnPropertyChanged("CurrentVolume");
				}
			}
		}

		public Quotation LastQuotation
		{
			get
			{
				return _lastQuotation;
			}
			set
			{
				if (_lastQuotation != value)
				{
					_lastQuotation = value;
					base.OnPropertyChanged("LastQuotation");
				}
			}
		}

		public DateTime ProcessedDay
		{
			get
			{
				return _processedDay;
			}
			set
			{
				if (_processedDay != value)
				{
					_processedDay = value;
					base.OnPropertyChanged("ProcessedDay");
				}
			}
		}

		public decimal Max
		{
			get
			{
				return _max;
			}
			set
			{
				if (_max != value)
				{
					_max = value;
					base.OnPropertyChanged("Max");
				}
			}
		}

		public decimal Min
		{
			get
			{
				return _min;
			}
			set
			{
				if (_min != value)
				{
					_min = value;
					base.OnPropertyChanged("Min");
				}
			}
		}

		public decimal MaxProfitThreshold
		{
			get
			{
				return _maxProfitThreshold;
			}
			set
			{
				if (_maxProfitThreshold != value)
				{
					_maxProfitThreshold = value;
					base.OnPropertyChanged("MaxProfitThreshold");
				}
			}
		}

		public DateTime BlockStart
		{
			get
			{
				return _blockStart;
			}
			set
			{
				if (_blockStart != value)
				{
					_blockStart = value;
					base.OnPropertyChanged("BlockStart");
				}
			}
		}

		#endregion

		#region Public Methods

		public DecisionEngineData()
		{
			this.State = DecisionEngineState.WaitingOpen;

			_min = decimal.MaxValue;
			_max = decimal.MinValue;
		}

		public void Copy(DecisionEngineData source)
		{
			this.State = source.State;
			this.StartValue = source.StartValue;
			this.HighThreshold = source.HighThreshold;
			this.LowThreshold = source.LowThreshold;
			this.StopLoss = source.StopLoss;
			this.CurrentVolume = source.CurrentVolume;
			this.ProcessedDay = source.ProcessedDay;
			this.PreviousState = source.PreviousState;
			this.Min = source.Min;
			this.Max = source.Max;
			this.MaxProfitThreshold = source.MaxProfitThreshold;
		}

		#endregion
	}
}
